﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace SkypeTranslater
{
	public sealed class SkypeFriend
	{
		public SkypeFriend()
		{
			DisplayName = string.Empty;
			UserHandle = string.Empty;
			FullName = string.Empty;
		}

		public string DisplayName { get; set; }
		public string UserHandle { get; set; }
		public string FullName { get; set; }

		public override string ToString()
		{
			return string.Format("{0} {1}", UserHandle, DisplayName);
		}
	}

	/// <summary>
	/// Interaction logic for NewGroupWindow.xaml
	/// </summary>
	public partial class NewGroupWindow
	{
		#region Dep prop
		public SkypeFriend SelectedFriend
		{
			get { return (SkypeFriend)GetValue(SelectedFriendProperty); }
			set { SetValue(SelectedFriendProperty, value); }
		}

		// Using a DependencyProperty as the backing store for SelectedFriend.  This enables animation, styling, binding, etc...
		public static readonly DependencyProperty SelectedFriendProperty =
			DependencyProperty.Register("SelectedFriend", typeof(SkypeFriend), typeof(NewGroupWindow), new UIPropertyMetadata(null));



		public List<SkypeFriend> FriendsCollection
		{
			get { return (List<SkypeFriend>)GetValue(FriendsCollectionProperty); }
			set { SetValue(FriendsCollectionProperty, value); }
		}

		// Using a DependencyProperty as the backing store for FriendsCollection.  This enables animation, styling, binding, etc...
		public static readonly DependencyProperty FriendsCollectionProperty =
			DependencyProperty.Register("FriendsCollection", typeof(List<SkypeFriend>), typeof(NewGroupWindow), new UIPropertyMetadata(null));

		public Group GroupContext
		{
			get { return (Group)GetValue(GroupContextProperty); }
			set { SetValue(GroupContextProperty, value); }
		}

		// Using a DependencyProperty as the backing store for GroupContext.  This enables animation, styling, binding, etc...
		public static readonly DependencyProperty GroupContextProperty =
			DependencyProperty.Register("GroupContext", typeof(Group), typeof(NewGroupWindow), new UIPropertyMetadata(null));
		#endregion

		public NewGroupWindow()
		{
			InitializeComponent();

			this.CommandBindings.Add(new CommandBinding(ApplicationCommands.New, (s, e) =>
			{
				e.Handled = true;
				if (this.SelectedFriend != null)
				{
					GroupContext.DisplayName = SelectedFriend.FullName;
					GroupContext.UserHandle = SelectedFriend.UserHandle;
				}
				this.DialogResult = true;
			}));

			this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Close, (s, e) =>
			{
				e.Handled = true;
				this.DialogResult = true;
			}));

			GroupContext = new Group() { FromLanguage = "en", ToLanguage = "ru", IsTraced = true };
			FriendsCollection = new List<SkypeFriend>();

			this.Loaded += new RoutedEventHandler(NewGroupWindow_Loaded);
		}

		void NewGroupWindow_Loaded(object sender, RoutedEventArgs e)
		{
			foreach (SKYPE4COMLib.User user in App.Skype.Friends)
			{
				FriendsCollection.Add(new SkypeFriend()
				{
					DisplayName = user.DisplayName,
					UserHandle = user.Handle,
					FullName = user.FullName
				});
			}
		}
	}
}
